package xyy.d3erpapi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

//异步处理请求配置类
@Configuration
public class AsyncConfig implements AsyncConfigurer {
    @Bean(name = "AsyncExecutor")
    public Executor AsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);  // 设置核心线程池大小
        executor.setMaxPoolSize(10);   // 设置最大线程池大小
        executor.setQueueCapacity(50); // 设置队列容量
        executor.setThreadNamePrefix("Async-"); // 设置线程名称前缀
        executor.setWaitForTasksToCompleteOnShutdown(true); // 等待任务完成
        executor.initialize(); // 初始化线程池
        return executor;
    }



    @Override
    public Executor getAsyncExecutor() {
        return AsyncExecutor();
    }
}
